package cn.edu.tju.se.records.dao.hibernate;

import java.util.List;

import org.springframework.stereotype.Repository;
import cn.edu.tju.se.base.dao.hibernate.BaseDaoImpl;
import cn.edu.tju.se.records.dao.PatientDao;
import cn.edu.tju.se.records.domain.Patient;
@Repository
public class PatientDaoImpl extends BaseDaoImpl<Patient> implements PatientDao{
	private final String GET_PATIENT_BY_PATIENTNAME = "from Patient p where p.patientname = ?";
	private final String GET_PATIENT_BY_PATIENTID = "from Patient p where p.patientid = ?";
	private final String GET_PATIENT_BY_DOCTORID = "from Patient p where p.doctorid = ?";
	
    @SuppressWarnings("unchecked")
	public Patient getPatientByPatientId(String PatientId){
		List<Patient> patient = (List<Patient>)find(GET_PATIENT_BY_PATIENTID,PatientId);
        if (patient.size() == 0) {
            return null;
        }else{
            return patient.get(0);
        }
    }
    
    @SuppressWarnings("unchecked")
	public Patient getPatientByPatientName(String PatientNmae){
        List<Patient> patient = (List<Patient>)find(GET_PATIENT_BY_PATIENTNAME,PatientNmae);
        if (patient.size() == 0) {
            return null;
        }else{
            return patient.get(0);
        }
    }
    
    @SuppressWarnings("unchecked")
	public List<Patient> getPatientByDoctorId(String DoctorId){
        List<Patient> patient = (List<Patient>)find(GET_PATIENT_BY_DOCTORID,DoctorId);
        if (patient.size() == 0) {
            return null;
        }else{
            return patient;
        }
    }
}
